import { mapMutations } from "vuex"

export default {
    data () {
        return {
            batchId: []
        }
    },
    methods: {
        edit (scope, item) {
            alert('编辑')
        },
        del (id) {
            let ids = [];
            // 不传id为批量删除
            if (id) {
                ids = [id]
            } else {
                ids = this.batchId;
            }
            if (!ids[0]) {
                return this.$message({
                    message: '至少选择一条数据',
                    type: 'warning'
                });
            }
            const h = this.$createElement;
            this.$msgbox({
                title: '提示',
                message: h('p', null, [
                    h('span', { style: 'line-height:100px;font-size:16px', }, '是否确定删除！ '),
                ]),
                showCancelButton: true,
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                center: true,
                beforeClose: async (action, instance, done) => {
                    if (action === 'confirm') {
                        instance.confirmButtonLoading = true;
                        instance.confirmButtonText = '执行中...';
                        try {
                            const res = await this.$api.delTable(ids);
                            this.$refs.grid.getData();
                            res && this.$notify({
                                title: '成功',
                                message: '删除成功！',
                                type: 'success'
                            });
                            this.$nextTick(() => {
                                this.$refs.grid.clearSelection()
                            })
                            this.batchId = []
                            done();
                            setTimeout(() => {
                                instance.confirmButtonLoading = false;
                            }, 500);
                        } catch (error) {
                            done();
                            instance.confirmButtonLoading = false;
                        }
                    } else {
                        done();
                    }
                }
            }).catch(() => {

            });
        },
        ...mapMutations(['SET_DETAILS'])
    },
}
